<?php
/**
 * 描述：船厂频道-船厂订单。
 * @final
 */
final class Exec_Shipyard_Ordersheet extends Exec
{
    public function Get()
    {
        #获取参数
        $type=Functions::UrlArgs('type');

        #定义标量
        $data=NULL;
        $params=NULL;
        $isLogin=FALSE;

        #执行程序
        $account=new Account(Account::Session('Username'),Account::Session('Password'));
        {
            $isLogin=$account->IsLogin();
        }
        $account=NULL;

        #执行动作
        switch($type)
        {
            case 'search':
                $shipyardName=Functions::UrlArgs('shipyardname');
                $shipownerName=Functions::UrlArgs('shipownername');
                $shiponwerNationality=Functions::UrlArgs('shiponwernationality');
                $amount=Functions::UrlArgs('amount');
                $giveDatetime_Year=Functions::UrlArgs('givedatetime_year');
                $giveDatetime_Month=Functions::UrlArgs('givedatetime_month');
                $datetime_Year=Functions::UrlArgs('datetime_year');
                $datetime_Month=Functions::UrlArgs('datetime_month');
                
                $sqlParams=array();                
                $sql='select * from shipyard_ordersheet where 1=1 ';
                {
                    if(!empty($shipyardName))
                    {
                        $sql=$sql.'and Shipyard_Name=? ';
                        $sqlParams[]=$shipyardName;
                        $params['shipyardname']=$shipyardName;
                    }

                    if(!empty($shipownerName))
                    {
                        $sql=$sql.'and Shipowner_Name=? ';
                        $sqlParams[]=$shipownerName;
                        $params['shipownername']=$shipownerName;
                    }

                    if(!empty($shiponwerNationality))
                    {
                        $sql=$sql.'and Shipyard_Nationality=? ';
                        $sqlParams[]=$shiponwerNationality;
                        $params['shiponwernationality']=$shiponwerNationality;
                    }

                    if(!empty($amount))
                    {
                        $sql=$sql.'and Amount=? ';
                        $sqlParams[]=$amount;
                        $params['amount']=$amount;
                    }

                    if(!empty($giveDatetime_Year))
                    {
                        $sql=$sql.'and year(GiveDatetime)=? ';
                        $sqlParams[]=$giveDatetime_Year;
                        $params['givedatetime_year']=$giveDatetime_Year;
                    }

                    if(!empty($giveDatetime_Month))
                    {
                        $sql=$sql.'and month(GiveDatetime)=? ';
                        $sqlParams[]=$giveDatetime_Month;
                        $params['givedatetime_month']=$giveDatetime_Month;
                    }

                    if(!empty($datetime_Year))
                    {
                        $sql=$sql.'and year(Datetime)=? ';
                        $sqlParams[]=$datetime_Year;
                        $params['datetime_year']=$datetime_Year;
                    }

                    if(!empty($datetime_Month))
                    {
                        $sql=$sql.'and month(Datetime)=? ';
                        $sqlParams[]=$datetime_Month;
                        $params['datetime_month']=$datetime_Month;
                    }
                }
                $sql=$sql.'order by ID desc limit ?,20';
                $data=DB::PGetData($sql,$sqlParams);
            break;
            default:
                $data=DB::GetData('select * from shipyard_ordersheet order by ID desc limit ?,20');
            break;
        }

        #渲染输出
        View::Assign('IsLogin',$isLogin);
        View::Assign('Ordersheets',$data['Record']);
        View::Assign('Params',$params);
        View::Assign('PageMenu',PagerFactory::Create('Common')->Fetch($data,array('URL'=>'exec.php?action=shipyard_ordersheet','IsDetail'=>TRUE,'Parameters'=>$params)));
        View::Display('shipyard/ordersheet.tpl');
    }
}
?>